package com.rongzhe.house.ui.fragment;

import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.rongzhe.house.R;
import com.rongzhe.house.manager.ConfigManager;
import com.rongzhe.house.presenter.HouseEntrustmentPresenter;
import com.rongzhe.house.ui.activity.HouseEntrustActivity;
import com.rongzhe.house.utils.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by huang on 2017/12/10.
 */

public class HouseEntrustmentFragment extends BaseFragment<HouseEntrustmentPresenter> {
    @BindView(R.id.btn_rent_input_online)
    Button btnRentInputOnline;
    Unbinder unbinder;

    @Override
    protected HouseEntrustmentPresenter createPresenter() {
        return new HouseEntrustmentPresenter(this);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_house_entrustment, container,
                false);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @OnClick(R.id.btn_rent_by_phone)
    public void rentByPhoneClick() {
        final String number = ConfigManager.getInstance().getServiceTel();
        Dialog dialog = UIUtils.createTwoButtonDialog(getContext(), getString(R.string.house_entrust),
                getString(R.string.call_to_entrust) + number, getString(android.R.string.cancel),
                getString(R.string.call_now), null, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+number));
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                    }
                });
        showAlert(dialog);
    }

    @OnClick(R.id.btn_rent_input_online)
    public void houseEntrustNow() {
        Intent intent = new Intent(getContext(), HouseEntrustActivity.class);
        startActivity(intent);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
